<?php
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use backend\utils\XHtml;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '权限管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header'); ?>
<?= $this->title . ' ' . XHtml::create('权限', ['group-create']) ?>
<?php $this->endBlock(); ?>
<div class="box box-primary">
    <div class="box-body">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'columns' => [
                'id',
                'name',
                [
                    'label' => '状态',
                    'value' => function ($data) {
                        return $data->status == 1 ? '开启' : '禁用';
                    }
                ],
                ['class' => yii\grid\ActionColumn::className(), 'header' => '操作', 'template' => '{update} {delete}',
                    'buttons' => [
                        'update' => function ($url, $model, $key) {
                            if ($model->id == 1) {
                                return "";
                            } else {
                                return Html::a('<span class="glyphicon glyphicon-pencil"></span>',
                                    Url::to(['group-update', 'id' => $model->id, 'page' => Yii::$app->request->get("page")]),
                                    ['title' => '修改']);
                            }
                        },
                        'delete' => function ($url, $model, $key) {
                            if ($model->id == 1) {
                                return "";
                            } else {
                                return Html::a('<span class="glyphicon glyphicon-trash"></span>',
                                    Url::to(['group-delete', 'id' => $model->id, 'page' => Yii::$app->request->get("page")]),
                                    [
                                        'title' => '删除',
                                        'data-confirm' => Yii::t('yii', '您确定要删除该条记录吗？删除后不能恢复。'),
                                    ]);
                            }
                        }
                    ]
                ],
            ]
        ]); ?>
    </div>
</div>
